<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>函数应用-数组操作-对象数组</title>
</head>
<body>

</body>
<script>

  /**
   * *
   *    filter
   *    find
   *    map
   * */

   var employees=[{
     id:1,
     name:'Mart',
     gender:'male',
     age:34
   },{
     id:2,
     name:'Mary',
     gender:'female',
     age:34
   },{
     id:1,
     name:'Martin',
     gender: 'male',
     age:32
   }];


   var males = employees.filter(function (emp){
       return emp.gender=='male';
   })
   var ages = employees.filter(function (emp){
      return emp.age>32;
   })

  var newers= employees.map(function (emp){

     return {
        id:emp.id,
        gender:emp.gender,
        age:emp.age-10
     }
  })

  /**使用三元运算符改造这段代码*/
  var newers2= employees.map(function (emp){

     if(emp.gender=='female'){
        emp.age-=10;
     }else {
         emp.age+=10;
     }

    return {
      id:emp.id,
      gender:emp.gender,
      age:emp.age
    }
  })

  console.log(newers2);




</script>
</html>